//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_admindialog.sqf"
#include "x_setup.sqf"

#include "x_uiinc.sqf"

private ["_display", "_ctrl", "_units", "_index"];
if (!X_Client) exitWith {};

disableSerialization;

if (isMultiplayer && !(serverCommandAvailable "#shutdown")) exitWith {
	[QGVAR(p_f_b_k), [player, GVAR(name_pl), 3]] call FUNC(NetCallEventCTS);
};

xr_phd_invulnerable = true;

createDialog "XD_AdminDialog";
_ctrl = __uiGetVar(D_ADMIN_DLG) displayCtrl 1001;

_units = if (isMultiplayer) then {(playableUnits - [objNull])} else {switchableUnits};
lbClear _ctrl;
{
	if (!isNull _x && {str _x != "HC_D_UNIT"}) then {
		_index = _ctrl lbAdd (name _x);
		_ctrl lbSetData [_index, str _x];
	};
} forEach _units;

_ctrl lbSetCurSel 0;
ctrlSetFocus (__uiGetVar(D_ADMIN_DLG) displayCtrl 1212);

0 spawn {
	scriptName "spawn_d_fnc_admindialog_kicker";
	private ["_ctrl", "_units", "_index"];
	disableSerialization;
	GVAR(a_d_p_kicked) = nil;
	_ctrl = __uiGetVar(D_ADMIN_DLG) displayCtrl 1001;
	while {alive player && {GVAR(admin_dialog_open)}} do {
		if (!isNil QGVAR(a_d_p_kicked)) then {
			GVAR(a_d_p_kicked) = nil;
			lbClear _ctrl;
			_units = if (isMultiplayer) then {(playableUnits - [objNull])} else {switchableUnits};
			{
				if (!isNull _x && {str _x != "HC_D_UNIT"}) then {
					_index = _ctrl lbAdd (name _x);
					_ctrl lbSetData [_index, str _x];
				};
			} forEach _units;
			_ctrl lbSetCurSel 0;
		};
		sleep 0.2;
	};
	if (GVAR(admin_dialog_open)) then {
		closeDialog 0;
	};
	xr_phd_invulnerable = false;
	sleep 0.5;
	deleteMarkerLocal QGVAR(admin_marker);
};